import React,{useState, useEffect} from 'react';
import Home from '../pages/Home/Home'
import Errorr from '../pages/404/Error'
import {BrowserRouter, Route, Redirect, Switch} from 'react-router-dom'

import {Admins} from '../types/index'

const data :Admins.BaseInfo = {
  username:'xin',
  password:'123123jkad',
  age:21,
  email:'213@qq.com',
  address:'北京市',
  phone:'12312313'
}
const routerItem = [
  {
    name: 'Home',
    path: '/home',
    exact: true,
    component: Home
  },
  {
    name: 'Error',
    path: '/error',
    exact: true,
    component: Errorr
  },
]
export default (props :any) => {
  const [name, setName] =  useState(data.username);

  return (
    <>
      <BrowserRouter>
        <Switch>
          {routerItem.map(router => (
            //返回每一个路由项目
            <Route 
            {...router}
            key = {router.name}
            ></Route>
          ))}
          <Redirect from='/' to='/home' exact></Redirect>
          <Redirect from='*' to='/error'></Redirect>
        </Switch>
      </BrowserRouter>
    </>
  )
}
